using System;
using System.Collections.Generic;

using OpenMetaverse;

namespace Playtime.RegionModule
{
	/// <summary>
	/// This class represents a specific set of attribute values, etc. related to
	/// one specific entity in the scene graph. E.g either an avatar or and object.
	/// </summary>
	public class ProfileInstance
	{
		/// <summary>
		/// The profile decribing the structure of this instance
		/// </summary>
		Profile mDescription;

		/// <summary>
		/// The executor reponsible for running scripts for this instance
		/// </summary>
		Executor mExecutor;
		
		public Dictionary<UUID, IAttributeInstance> Values { get; private set; }

		public ProfileInstance(Profile p, bool luaAllowCollectGarbage)
		{
			mDescription = p;

			// set up array of values
			Values = new Dictionary<UUID, IAttributeInstance>();
			foreach(Attribute a in mDescription.Attributes.Values)
			{
				IAttributeInstance v = a.CreateInstance();
				Values.Add(a.ID, v);
			}
			
			if(!string.IsNullOrEmpty(p.ScriptCode))
				mExecutor = new Executor(this, luaAllowCollectGarbage, p.ScriptCode);
		}
		
		public void ExecuteInitializeHook()
		{
			mExecutor.ExecuteInitializeHook();
		}
	}
}

